
export default {
  data() {
    return {
      appealInfo: '',
      appealAdd: '',

      reconstruction: true,

      dialogVisible: false,
      dialogLoading: false,
      dialogTitle: '添加申诉',
      footerBtns: [],
      dialogSelect: {}
    }
  },
  computed: {
    params() {
      return this.$parent.$refs.filterForm.getParms()
    }
  },
  mounted() {
    this.footerBtns = [
      {
        text: '提交',
        type: 'primary',
        loading: this.dialogLoading,
        trigger: 'submit'
      },
      {
        text: '取消',
        type: 'info',
        trigger: 'cancel'
      }
    ]
  },
  filters: {
    yardName(val) {
      let name = ''

      switch (val) {
        case 1:
          name = '三香'
          break
        case 2:
          name = '浒关'
          break
      }

      return name
    }
  },
  methods: {
    appealFun(row) {
      this.appealInfo({
        id: row.id,
        num: row.num,
        yard: row.yard
      }).then(res => {
        if (res.code === 200) {
          this.dialogSelect = res.data
          this.dialogVisible = true
        } else {
          this.$message.error('获取数据失败')
        }
      })
    },

    dialogSubmit() {
      this.$refs.dialogSelectForm.validate((valid) => {
        if (valid) {
          const fileId = []
          if (this.fileList && this.fileList.length) {
            this.fileList.forEach(item => {
              fileId.push(item.url)
            })
          }

          const params = {
            num: this.dialogSelect.num,
            yard: this.dialogSelect.yard,
            subjectId: this.dialogSelect.subjectId,
            file: fileId,
            memo: this.dialogSelect.memo
          }

          this.dialogLoading = true
          this.footerBtns[0].loading = true

          this.appealAdd(params).then(res => {
            this.dialogLoading = false
            this.footerBtns[0].loading = false
            if (res.code === 200) {
              this.$message.success('申诉成功')
              this.getData()
              this.dialogCancel()
            } else {
              this.$message.error(res.message)
            }
          })
        }
      })
    },

    dialogCancel() {
      this.fileList = []
      this.dialogVisible = false
    }
  }
}
